From 9e8aa7bfe364077f47f76c071c43b53a43748ca4 Mon Sep 17 00:00:00 2001 From: Joshua Chen Date: Sun, 25 May 2025 17:25:12 +0800 Subject: [PATCH] Lint: prefer Object.hasOwn, avoid eval --- .../web/api/htmlbuttonelement/popovertargetaction/index.md | 4 ++-- .../api/htmlbuttonelement/popovertargetelement/index.md | 2 +- files/en-us/web/api/htmlelement/popover/index.md | 2 +- files/en-us/web/api/htmlelement/togglepopover/index.md | 4 ++-- .../web/api/htmlinputelement/popovertargetaction/index.md | 4 ++-- .../web/api/htmlinputelement/popovertargetelement/index.md | 4 ++-- files/en-us/web/api/popover_api/using/index.md | 2 +- .../en-us/web/api/rtccertificate/getfingerprints/index.md | 2 +- files/en-us/web/html/reference/elements/template/index.md | 6 ++++-- .../proxy_auto-configuration_pac_file/index.md | 7 ++----- .../javascript/guide/expressions_and_operators/index.md | 1 - 11 files changed, 18 insertions(+), 20 deletions(-) diff --git a/files/en-us/web/api/htmlbuttonelement/popovertargetaction/index.md b/files/en-us/web/api/htmlbuttonelement/popovertargetaction/index.md index d0c8234ab979ea1..180f259fee4f8ae 100644 --- a/files/en-us/web/api/htmlbuttonelement/popovertargetaction/index.md +++ b/files/en-us/web/api/htmlbuttonelement/popovertargetaction/index.md @@ -47,7 +47,7 @@ const toggleBtn = document.getElementById("toggleBtn"); // Check for popover API support. function supportsPopover() { - return HTMLElement.prototype.hasOwnProperty("popover"); + return Object.hasOwn(HTMLElement.prototype, "popover"); } ``` @@ -94,7 +94,7 @@ A `manual` popover must be closed explicitly, and not "light dismissed" by selec ```js function supportsPopover() { - return HTMLElement.prototype.hasOwnProperty("popover"); + return Object.hasOwn(HTMLElement.prototype, "popover"); } const popover = document.getElementById("mypopover"); diff --git a/files/en-us/web/api/htmlbuttonelement/popovertargetelement/index.md b/files/en-us/web/api/htmlbuttonelement/popovertargetelement/index.md index 30327bccd41324c..47464c20c47d9c4 100644 --- a/files/en-us/web/api/htmlbuttonelement/popovertargetelement/index.md +++ b/files/en-us/web/api/htmlbuttonelement/popovertargetelement/index.md @@ -45,7 +45,7 @@ const toggleBtn = document.getElementById("toggleBtn"); // Check for popover API support. function supportsPopover() { - return HTMLElement.prototype.hasOwnProperty("popover"); + return Object.hasOwn(HTMLElement.prototype, "popover"); } ``` diff --git a/files/en-us/web/api/htmlelement/popover/index.md b/files/en-us/web/api/htmlelement/popover/index.md index d53bccb339b87a5..003ae414fecbaab 100644 --- a/files/en-us/web/api/htmlelement/popover/index.md +++ b/files/en-us/web/api/htmlelement/popover/index.md @@ -42,7 +42,7 @@ You can use the `popover` attribute to feature detect the [Popover API](/en-US/d ```js function supportsPopover() { - return HTMLElement.prototype.hasOwnProperty("popover"); + return Object.hasOwn(HTMLElement.prototype, "popover"); } ``` diff --git a/files/en-us/web/api/htmlelement/togglepopover/index.md b/files/en-us/web/api/htmlelement/togglepopover/index.md index 2d1c1f3e888585b..27bdb4d0d506dfd 100644 --- a/files/en-us/web/api/htmlelement/togglepopover/index.md +++ b/files/en-us/web/api/htmlelement/togglepopover/index.md @@ -95,7 +95,7 @@ First we check whether popovers are supported, and if they aren't we hide the po const instructions = document.getElementById("instructions"); const popover = document.getElementById("mypopover"); -if (!HTMLElement.prototype.hasOwnProperty("popover")) { +if (!Object.hasOwn(HTMLElement.prototype, "popover")) { popover.innerText = ""; instructions.innerText = "Popovers not supported"; } @@ -105,7 +105,7 @@ If popovers are supported we add a listener for the `h` key to be pressed, and u We also log whether the popup was open or closed after the call, but only if a `true` or `false` was returned. ```js -if (HTMLElement.prototype.hasOwnProperty("popover")) { +if (Object.hasOwn(HTMLElement.prototype, "popover")) { document.addEventListener("keydown", (event) => { if (event.key === "h") { const popupOpened = popover.togglePopover(); diff --git a/files/en-us/web/api/htmlinputelement/popovertargetaction/index.md b/files/en-us/web/api/htmlinputelement/popovertargetaction/index.md index 173bc84112ab980..53d16c263c0cc6a 100644 --- a/files/en-us/web/api/htmlinputelement/popovertargetaction/index.md +++ b/files/en-us/web/api/htmlinputelement/popovertargetaction/index.md @@ -47,7 +47,7 @@ const toggleBtn = document.getElementById("toggleBtn"); // Check for popover API support. function supportsPopover() { - return HTMLElement.prototype.hasOwnProperty("popover"); + return Object.hasOwn(HTMLElement.prototype, "popover"); } ``` @@ -94,7 +94,7 @@ A `manual` popover must be closed explicitly, and not "light dismissed" by selec ```js function supportsPopover() { - return HTMLElement.prototype.hasOwnProperty("popover"); + return Object.hasOwn(HTMLElement.prototype, "popover"); } const popover = document.getElementById("mypopover"); diff --git a/files/en-us/web/api/htmlinputelement/popovertargetelement/index.md b/files/en-us/web/api/htmlinputelement/popovertargetelement/index.md index 28690da292aba35..9b828d027e85d27 100644 --- a/files/en-us/web/api/htmlinputelement/popovertargetelement/index.md +++ b/files/en-us/web/api/htmlinputelement/popovertargetelement/index.md @@ -25,7 +25,7 @@ A reference to a popover element in the DOM. ```js function supportsPopover() { - return HTMLElement.prototype.hasOwnProperty("popover"); + return Object.hasOwn(HTMLElement.prototype, "popover"); } const popover = document.getElementById("mypopover"); @@ -64,7 +64,7 @@ const toggleBtn = document.getElementById("toggleBtn"); // Check for popover API support. function supportsPopover() { - return HTMLElement.prototype.hasOwnProperty("popover"); + return Object.hasOwn(HTMLElement.prototype, "popover"); } ``` diff --git a/files/en-us/web/api/popover_api/using/index.md b/files/en-us/web/api/popover_api/using/index.md index 858121ee7eda825..f223e70b0edca55 100644 --- a/files/en-us/web/api/popover_api/using/index.md +++ b/files/en-us/web/api/popover_api/using/index.md @@ -102,7 +102,7 @@ The {{domxref("HTMLElement.popover")}} property can be used to get or set the [` ```js function supportsPopover() { - return HTMLElement.prototype.hasOwnProperty("popover"); + return Object.hasOwn(HTMLElement.prototype, "popover"); } ``` diff --git a/files/en-us/web/api/rtccertificate/getfingerprints/index.md b/files/en-us/web/api/rtccertificate/getfingerprints/index.md index ce35c71a76023c2..caaa70c74704edd 100644 --- a/files/en-us/web/api/rtccertificate/getfingerprints/index.md +++ b/files/en-us/web/api/rtccertificate/getfingerprints/index.md @@ -100,7 +100,7 @@ let serverFingerprintDict = Object.fromEntries( // and all common properties match. function compareObjects(obj1, obj2) { const commonProperties = Object.keys(obj1).filter((prop) => - obj2.hasOwnProperty(prop), + Object.hasOwn(obj2, prop), ); // Return false if there are no common properties if (Object.keys(commonProperties).length === 0) return false; diff --git a/files/en-us/web/html/reference/elements/template/index.md b/files/en-us/web/html/reference/elements/template/index.md index 247ad10d0512499..7c9a8279bb8a06f 100644 --- a/files/en-us/web/html/reference/elements/template/index.md +++ b/files/en-us/web/html/reference/elements/template/index.md @@ -177,8 +177,10 @@ In this example, a hidden support warning is included at the beginning of the ma ``` ```js -const isShadowRootModeSupported = - HTMLTemplateElement.prototype.hasOwnProperty("shadowRootMode"); +const isShadowRootModeSupported = Object.hasOwn( + HTMLTemplateElement.prototype, + "shadowRootMode", +); document .querySelector("p[hidden]") diff --git a/files/en-us/web/http/guides/proxy_servers_and_tunneling/proxy_auto-configuration_pac_file/index.md b/files/en-us/web/http/guides/proxy_servers_and_tunneling/proxy_auto-configuration_pac_file/index.md index ddd265636ed6f92..b58a098abf9afec 100644 --- a/files/en-us/web/http/guides/proxy_servers_and_tunneling/proxy_auto-configuration_pac_file/index.md +++ b/files/en-us/web/http/guides/proxy_servers_and_tunneling/proxy_auto-configuration_pac_file/index.md @@ -243,12 +243,9 @@ Pattern and mask specification is done the same way as for SOCKS configuration. #### Examples ```js -function alertEval(str) { - alert(`${str} is ${eval(str)}`); -} function FindProxyForURL(url, host) { - alertEval('isInNet(host, "192.0.2.172", "255.255.255.255")'); - // "PAC-alert: isInNet(host, "192.0.2.172", "255.255.255.255") is true" + alert(isInNet(host, "192.0.2.172", "255.255.255.255")); + // "PAC-alert: true" } ``` diff --git a/files/en-us/web/javascript/guide/expressions_and_operators/index.md b/files/en-us/web/javascript/guide/expressions_and_operators/index.md index b0c3386e65b06c8..656d2a2b332169a 100644 --- a/files/en-us/web/javascript/guide/expressions_and_operators/index.md +++ b/files/en-us/web/javascript/guide/expressions_and_operators/index.md @@ -971,7 +971,6 @@ For methods and functions, the `typeof` operator returns results as follows: ```js typeof blur; // returns "function" -typeof eval; // returns "function" typeof parseInt; // returns "function" typeof shape.split; // returns "function" ```